package NextClass;


import NextClass.Native.HttpService;
import NextClass.Native.NextFile;

import java.io.File;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.util.Arrays;
import com.sun.net.httpserver.HttpServer;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpExchange;
import vm.runtime.NextVMRuntime;

public class NativeClass {
    public String ClassName = null;
    public String[] Methods = null;
    public Object InitObject = null;

    public void Init(String InitClass, Object... InputObj) throws IOException {
        if (InitClass.equals("file")) {
            this.InitObject = new File(String.valueOf(InputObj[0]));
        }
        else if (InitClass.equals("http_service")) {
            String ipAddress = (String) InputObj[0];
            int port = (int) InputObj[1];

            // 创建HttpServer实例，并绑定到指定IP和端口
            this.InitObject = HttpServer.create(new InetSocketAddress(ipAddress, port), 0);
        }
    }

    public Object run(String InvokeMethod, NextVMRuntime nextVMRuntime, Object... objects) throws Exception{
        if (this.ClassName.equals("file")) {
            return NextFile.run(InvokeMethod,nextVMRuntime,InitObject,objects);
        }
        else if (this.ClassName.equals("http_service")) {
            return HttpService.run(InvokeMethod,InitObject,nextVMRuntime,objects);
        }
        return null;
    }
}
